home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / ax3.00 / mydiranywhere.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-03  |  2.7 KB  |  133 lines

  1. #include "bbs.h"
  2.  
  3. static void MyDirProtect(long bits,char *ps)
  4. {
  5.  long c,x,y;
  6.  char pbits[] = { 'd','e','w','r','a','p','s','h' };
  7.  
  8.  y=1;
  9.  c=bits^15;
  10.  
  11.  for(x=0; x<8; x++) {
  12.      if((c&y)==y)        ps[7-x]=pbits[x];
  13.      y=y<<1;
  14.     }
  15. }
  16.  
  17.  
  18. static void MyDirDisplay(struct FileInfoBlock *f_info)
  19. {
  20.  long t,h,m,s;
  21.  char ans[10],date[20];
  22.  struct tm *ut;
  23.  
  24.  t=((f_info->fib_Date.ds_Days+2914L)*86400L);
  25.  t+=(f_info->fib_Date.ds_Minute*60);
  26.  t+=712800L;
  27.  h=(f_info->fib_Date.ds_Minute/60);
  28.  m=((f_info->fib_Date.ds_Minute)-(h*60));
  29.  s=(f_info->fib_Date.ds_Tick/50);
  30.  t+=s;
  31.  t=t-21601L;
  32.  ut=gmtime(&t);
  33.  
  34.  if(ut->tm_year>100)     ut->tm_year-=100;
  35.  sprintf(date,"%02d-%02d-%02d",ut->tm_mon+1,ut->tm_mday,ut->tm_year);
  36.  
  37.  t=t+21601L;
  38.  strcpy(ans,"--------");
  39.  MyDirProtect(f_info->fib_Protection,ans);
  40.  
  41.  if(!(f_info->fib_EntryType>0))
  42.          sprintf(GSTR3,"%8ld",f_info->fib_Size);
  43.  else    strcpy(GSTR3,"     Dir");
  44.  
  45.  sprintf(GSTR2," %-25s %s %s %s %02ld:%02ld:%02ld\r\n",f_info->fib_FileName, \
  46.     GSTR3,ans,date,h,m,s);
  47.  AEPutStr(GSTR2);
  48. }
  49.  
  50. static void MyDirRecurse(char *path,UBYTE cflag)
  51. {
  52.  int stat=0;
  53.  BPTR lock;
  54.  struct FileInfoBlock *f_info;
  55.  
  56.  if((f_info=(struct FileInfoBlock *) \
  57.    AllocDosObject(DOS_FIB,NULL))==NULL)
  58.         return;
  59.  
  60.  if((lock=Lock(path,ACCESS_READ))==0) {
  61.      FreeDosObject(DOS_FIB,f_info);
  62.         return;
  63.     }
  64.  
  65.  if((Examine(lock,f_info))==0) {
  66.         sprintf(GSTR2,"%s does not exist\r\n",path);
  67.         AEPutStr(GSTR2);
  68.         UnLock(lock);
  69.         FreeDosObject(DOS_FIB,f_info);
  70.         return;
  71.     }
  72.  
  73.  LineCount=0;
  74.  if(f_info->fib_EntryType>0)    {
  75.      sprintf(GSTR2,"Directory of %s\r\n",path);
  76.         AEPutStr(GSTR2);
  77.  
  78.      while(((ExNext(lock,f_info))!=0)&&(!stat)) {
  79.          MyDirDisplay(f_info);
  80.             stat=CheckForPause();
  81.             if(cflag&&!stat&&f_info->fib_Comment[0]!='\0') {
  82.              AEPutStr(" : ");
  83.                 AEPutStr(f_info->fib_Comment);
  84.                 AEPutStr("\r\n");
  85.                 stat=CheckForPause();
  86.             }
  87.         }
  88.     } else    MyDirDisplay(f_info);
  89.  
  90.  UnLock(lock);
  91.  FreeDosObject(DOS_FIB,f_info);
  92.  return;
  93. }
  94.  
  95. void MyDirAnyWhere(void)
  96. {
  97.  long stat;
  98.  UBYTE comments;
  99.  
  100.  gnsflag=comments=0;
  101.  
  102.  AEPutStr("\r\n");
  103.  stat=CommandSplit();
  104.  if(stat>1)    {
  105.      strcpy(GSTR1,Command[1]);
  106.         if(stat>2)    {
  107.          if(Command[2][0]=='C'||Command[2][0]=='c')
  108.                 comments=1;
  109.         }
  110.     } else    {
  111.      comments=1;
  112.         AEPutStr("FullPath for directory? ");
  113.         stat=LineInput("",GSTR1,250,KEYBOARD_TIMEOUT);
  114.         if(stat<0||GSTR1[0]=='\0')    {
  115.          AEPutStr("\r\n");
  116.             return;
  117.         }
  118.           if(FindAssign(GSTR1))
  119.           {
  120.              AEPutStr("\r\nDevice not Mounted.\r\n");
  121.              AEPutStr("\r\n");
  122.              return;
  123.           }
  124.      AEPutStr("Include comments (Y/n)? ");
  125.         stat=LineInput("",GSTR2,3,KEYBOARD_TIMEOUT);
  126.      if(stat<0)        return;
  127.  
  128.      if(GSTR2[0]=='n'||GSTR2[0]=='N')        comments=0;
  129.     }
  130.  MyDirRecurse(GSTR1,comments);
  131.  AEPutStr("\r\n");
  132. }
  133.